###########################################################################
#
#   Copyright 2010 American Public Media Group
#
#   This file is part of AIR2.
#
#   AIR2 is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   AIR2 is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
#
###########################################################################

package AIR2::User;

use strict;

use base qw(AIR2::DB);

__PACKAGE__->meta->setup(
    table => 'user',

    columns => [
        user_id   => { type => 'serial', not_null => 1 },
        user_uuid => {
            type     => 'character',
            length   => 12,
            not_null => 1
        },
        user_username => { type => 'varchar',   length => 255 },
        user_password => { type => 'character', length => 32 },
        user_first_name =>
            { type => 'varchar', default => '', length => 64, not_null => 1 },
        user_last_name =>
            { type => 'varchar', default => '', length => 64, not_null => 1 },
        user_pref      => { type => 'text', length => 65535 },
        user_type => {
            type     => 'character',
            default  => 'A',
            length   => 1,
            not_null => 1
        },
        user_status => {
            type     => 'character',
            default  => 'A',
            length   => 1,
            not_null => 1
        },
        user_cre_user => { type => 'integer' },
        user_upd_user => { type => 'integer' },
        user_cre_dtim => {
            type     => 'datetime',
            not_null => 1
        },
        user_upd_dtim  => { type => 'datetime' },
        user_pswd_dtim => { type => 'datetime' },
    ],

    primary_key_columns => ['user_id'],

    unique_keys => [ ['user_username'], ['user_uuid'], ],

    foreign_keys => [
        cre_user => {
            class       => 'AIR2::User',
            key_columns => { user_cre_user => 'user_id' },
        },

        upd_user => {
            class       => 'AIR2::User',
            key_columns => { user_upd_user => 'user_id' },
        },
    ],

    relationships => [
        activity_master => {
            class      => 'AIR2::ActivityMaster',
            column_map => { user_id => 'actm_cre_user' },
            type       => 'one to many',
        },

        activity_master_updated => {
            class      => 'AIR2::ActivityMaster',
            column_map => { user_id => 'actm_upd_user' },
            type       => 'one to many',
        },

        admin_role => {
            class      => 'AIR2::AdminRole',
            column_map => { user_id => 'ar_cre_user' },
            type       => 'one to many',
        },

        admin_role_updated => {
            class      => 'AIR2::AdminRole',
            column_map => { user_id => 'ar_upd_user' },
            type       => 'one to many',
        },

        batch => {
            class      => 'AIR2::Batch',
            column_map => { user_id => 'batch_cre_user' },
            type       => 'one to many',
        },

        batch_objects => {
            class      => 'AIR2::Batch',
            column_map => { user_id => 'batch_user_id' },
            type       => 'one to many',
        },

        batch_updated => {
            class      => 'AIR2::Batch',
            column_map => { user_id => 'batch_upd_user' },
            type       => 'one to many',
        },

        batch_src => {
            class      => 'AIR2::BatchSrc',
            column_map => { user_id => 'bsrc_cre_user' },
            type       => 'one to many',
        },

        batch_src_updated => {
            class      => 'AIR2::BatchSrc',
            column_map => { user_id => 'bsrc_upd_user' },
            type       => 'one to many',
        },

        code_master => {
            class      => 'AIR2::CodeMaster',
            column_map => { user_id => 'cm_cre_user' },
            type       => 'one to many',
        },

        code_master_updated => {
            class      => 'AIR2::CodeMaster',
            column_map => { user_id => 'cm_upd_user' },
            type       => 'one to many',
        },

        fact => {
            class      => 'AIR2::Fact',
            column_map => { user_id => 'fact_cre_user' },
            type       => 'one to many',
        },

        fact_updated => {
            class      => 'AIR2::Fact',
            column_map => { user_id => 'fact_upd_user' },
            type       => 'one to many',
        },

        fact_value => {
            class      => 'AIR2::FactValue',
            column_map => { user_id => 'fv_cre_user' },
            type       => 'one to many',
        },

        fact_value_updated => {
            class      => 'AIR2::FactValue',
            column_map => { user_id => 'fv_upd_user' },
            type       => 'one to many',
        },

        inquiry => {
            class      => 'AIR2::Inquiry',
            column_map => { user_id => 'inq_cre_user' },
            type       => 'one to many',
        },

        inquiry_updated => {
            class      => 'AIR2::Inquiry',
            column_map => { user_id => 'inq_upd_user' },
            type       => 'one to many',
        },

        iptc_master => {
            class      => 'AIR2::IptcMaster',
            column_map => { user_id => 'iptc_cre_user' },
            type       => 'one to many',
        },

        iptc_master_updated => {
            class      => 'AIR2::IptcMaster',
            column_map => { user_id => 'iptc_upd_user' },
            type       => 'one to many',
        },

        org_sys_id => {
            class      => 'AIR2::OrgSysId',
            column_map => { user_id => 'osid_cre_user' },
            type       => 'one to many',
        },

        org_sys_id_updated => {
            class      => 'AIR2::OrgSysId',
            column_map => { user_id => 'osid_upd_user' },
            type       => 'one to many',
        },

        organization => {
            class      => 'AIR2::Organization',
            column_map => { user_id => 'org_cre_user' },
            type       => 'one to many',
        },

        organization_updated => {
            class      => 'AIR2::Organization',
            column_map => { user_id => 'org_upd_user' },
            type       => 'one to many',
        },

        preference_type => {
            class      => 'AIR2::PreferenceType',
            column_map => { user_id => 'pt_cre_user' },
            type       => 'one to many',
        },

        preference_type_updated => {
            class      => 'AIR2::PreferenceType',
            column_map => { user_id => 'pt_upd_user' },
            type       => 'one to many',
        },

        preference_type_value => {
            class      => 'AIR2::PreferenceTypeValue',
            column_map => { user_id => 'ptv_cre_user' },
            type       => 'one to many',
        },

        preference_type_value_updated => {
            class      => 'AIR2::PreferenceTypeValue',
            column_map => { user_id => 'ptv_upd_user' },
            type       => 'one to many',
        },

        project => {
            class      => 'AIR2::Project',
            column_map => { user_id => 'prj_cre_user' },
            type       => 'one to many',
        },

        project_activity => {
            class      => 'AIR2::ProjectActivity',
            column_map => { user_id => 'pa_cre_user' },
            type       => 'one to many',
        },

        project_activity_objects => {
            class      => 'AIR2::ProjectActivity',
            column_map => { user_id => 'pa_user_id' },
            type       => 'one to many',
        },

        project_activity_updated => {
            class      => 'AIR2::ProjectActivity',
            column_map => { user_id => 'pa_upd_user' },
            type       => 'one to many',
        },

        project_annotation => {
            class      => 'AIR2::ProjectAnnotation',
            column_map => { user_id => 'prjan_cre_user' },
            type       => 'one to many',
        },

        project_annotation_updated => {
            class      => 'AIR2::ProjectAnnotation',
            column_map => { user_id => 'prjan_upd_user' },
            type       => 'one to many',
        },

        project_inquiry => {
            class      => 'AIR2::ProjectInquiry',
            column_map => { user_id => 'pinq_cre_user' },
            type       => 'one to many',
        },

        project_inquiry_updated => {
            class      => 'AIR2::ProjectInquiry',
            column_map => { user_id => 'pinq_upd_user' },
            type       => 'one to many',
        },

        project_message => {
            class      => 'AIR2::ProjectMessage',
            column_map => { user_id => 'pm_cre_user' },
            type       => 'one to many',
        },

        project_message_updated => {
            class      => 'AIR2::ProjectMessage',
            column_map => { user_id => 'pm_upd_user' },
            type       => 'one to many',
        },

        project_updated => {
            class      => 'AIR2::Project',
            column_map => { user_id => 'prj_upd_user' },
            type       => 'one to many',
        },

        project_org => {
            class      => 'AIR2::ProjectOrg',
            column_map => { user_id => 'porg_cre_user' },
            type       => 'one to many',
        },

        project_org_objects => {
            class      => 'AIR2::ProjectOrg',
            column_map => { user_id => 'porg_contact_user_id' },
            type       => 'one to many',
        },

        project_org_updated => {
            class      => 'AIR2::ProjectOrg',
            column_map => { user_id => 'porg_upd_user' },
            type       => 'one to many',
        },

        project_outcome => {
            class      => 'AIR2::ProjectOutcome',
            column_map => { user_id => 'prjo_cre_user' },
            type       => 'one to many',
        },

        project_outcome_updated => {
            class      => 'AIR2::ProjectOutcome',
            column_map => { user_id => 'prjo_upd_user' },
            type       => 'one to many',
        },

        question => {
            class      => 'AIR2::Question',
            column_map => { user_id => 'ques_cre_user' },
            type       => 'one to many',
        },

        question_updated => {
            class      => 'AIR2::Question',
            column_map => { user_id => 'ques_upd_user' },
            type       => 'one to many',
        },

        sma_annotation => {
            class      => 'AIR2::SmaAnnotation',
            column_map => { user_id => 'smaan_cre_user' },
            type       => 'one to many',
        },

        sma_annotation_updated => {
            class      => 'AIR2::SmaAnnotation',
            column_map => { user_id => 'smaan_upd_user' },
            type       => 'one to many',
        },

        source => {
            class      => 'AIR2::Source',
            column_map => { user_id => 'src_cre_user' },
            type       => 'one to many',
        },

        source_updated => {
            class      => 'AIR2::Source',
            column_map => { user_id => 'src_upd_user' },
            type       => 'one to many',
        },

        specialty => {
            class      => 'AIR2::Specialty',
            column_map => { user_id => 'spec_cre_user' },
            type       => 'one to many',
        },

        specialty_updated => {
            class      => 'AIR2::Specialty',
            column_map => { user_id => 'spec_upd_user' },
            type       => 'one to many',
        },

        sr_annotation => {
            class      => 'AIR2::SrAnnotation',
            column_map => { user_id => 'sran_cre_user' },
            type       => 'one to many',
        },

        sr_annotation_updated => {
            class      => 'AIR2::SrAnnotation',
            column_map => { user_id => 'sran_upd_user' },
            type       => 'one to many',
        },

        src_activity => {
            class      => 'AIR2::SrcActivity',
            column_map => { user_id => 'sact_cre_user' },
            type       => 'one to many',
        },

        src_activity_updated => {
            class      => 'AIR2::SrcActivity',
            column_map => { user_id => 'sact_upd_user' },
            type       => 'one to many',
        },

        src_alias => {
            class      => 'AIR2::SrcAlias',
            column_map => { user_id => 'sa_cre_user' },
            type       => 'one to many',
        },

        src_alias_updated => {
            class      => 'AIR2::SrcAlias',
            column_map => { user_id => 'sa_upd_user' },
            type       => 'one to many',
        },

        src_annotation => {
            class      => 'AIR2::SrcAnnotation',
            column_map => { user_id => 'srcan_cre_user' },
            type       => 'one to many',
        },

        src_annotation_updated => {
            class      => 'AIR2::SrcAnnotation',
            column_map => { user_id => 'srcan_upd_user' },
            type       => 'one to many',
        },

        src_credential => {
            class      => 'AIR2::SrcCredential',
            column_map => { user_id => 'sc_cre_user' },
            type       => 'one to many',
        },

        src_credential_updated => {
            class      => 'AIR2::SrcCredential',
            column_map => { user_id => 'sc_upd_user' },
            type       => 'one to many',
        },

        src_email => {
            class      => 'AIR2::SrcEmail',
            column_map => { user_id => 'sem_cre_user' },
            type       => 'one to many',
        },

        src_email_updated => {
            class      => 'AIR2::SrcEmail',
            column_map => { user_id => 'sem_upd_user' },
            type       => 'one to many',
        },

        src_fact => {
            class      => 'AIR2::SrcFact',
            column_map => { user_id => 'sf_cre_user' },
            type       => 'one to many',
        },

        src_fact_updated => {
            class      => 'AIR2::SrcFact',
            column_map => { user_id => 'sf_upd_user' },
            type       => 'one to many',
        },

        src_inquiry => {
            class      => 'AIR2::SrcInquiry',
            column_map => { user_id => 'si_cre_user' },
            type       => 'one to many',
        },

        src_inquiry_updated => {
            class      => 'AIR2::SrcInquiry',
            column_map => { user_id => 'si_upd_user' },
            type       => 'one to many',
        },

        src_mail_address => {
            class      => 'AIR2::SrcMailAddress',
            column_map => { user_id => 'smadd_cre_user' },
            type       => 'one to many',
        },

        src_mail_address_updated => {
            class      => 'AIR2::SrcMailAddress',
            column_map => { user_id => 'smadd_upd_user' },
            type       => 'one to many',
        },

        src_media_asset => {
            class      => 'AIR2::SrcMediaAsset',
            column_map => { user_id => 'sma_cre_user' },
            type       => 'one to many',
        },

        src_media_asset_updated => {
            class      => 'AIR2::SrcMediaAsset',
            column_map => { user_id => 'sma_upd_user' },
            type       => 'one to many',
        },

        src_org => {
            class      => 'AIR2::SrcOrg',
            column_map => { user_id => 'so_cre_user' },
            type       => 'one to many',
        },

        src_org_updated => {
            class      => 'AIR2::SrcOrg',
            column_map => { user_id => 'so_upd_user' },
            type       => 'one to many',
        },

        src_phone_number => {
            class      => 'AIR2::SrcPhoneNumber',
            column_map => { user_id => 'sph_cre_user' },
            type       => 'one to many',
        },

        src_phone_number_updated => {
            class      => 'AIR2::SrcPhoneNumber',
            column_map => { user_id => 'sph_upd_user' },
            type       => 'one to many',
        },

        src_pref_org => {
            class      => 'AIR2::SrcPrefOrg',
            column_map => { user_id => 'spo_cre_user' },
            type       => 'one to many',
        },

        src_pref_org_updated => {
            class      => 'AIR2::SrcPrefOrg',
            column_map => { user_id => 'spo_upd_user' },
            type       => 'one to many',
        },

        src_preference => {
            class      => 'AIR2::SrcPreference',
            column_map => { user_id => 'sp_cre_user' },
            type       => 'one to many',
        },

        src_preference_updated => {
            class      => 'AIR2::SrcPreference',
            column_map => { user_id => 'sp_upd_user' },
            type       => 'one to many',
        },

        src_relationship => {
            class      => 'AIR2::SrcRelationship',
            column_map => { user_id => 'srel_cre_user' },
            type       => 'one to many',
        },

        src_relationship_updated => {
            class      => 'AIR2::SrcRelationship',
            column_map => { user_id => 'srel_upd_user' },
            type       => 'one to many',
        },

        src_response => {
            class      => 'AIR2::SrcResponse',
            column_map => { user_id => 'sr_cre_user' },
            type       => 'one to many',
        },

        src_response_updated => {
            class      => 'AIR2::SrcResponse',
            column_map => { user_id => 'sr_upd_user' },
            type       => 'one to many',
        },

        src_response_set => {
            class      => 'AIR2::SrcResponseSet',
            column_map => { user_id => 'srs_cre_user' },
            type       => 'one to many',
        },

        src_response_set_updated => {
            class      => 'AIR2::SrcResponseSet',
            column_map => { user_id => 'srs_upd_user' },
            type       => 'one to many',
        },

        src_specialty => {
            class      => 'AIR2::SrcSpecialty',
            column_map => { user_id => 'ss_cre_user' },
            type       => 'one to many',
        },

        src_specialty_updated => {
            class      => 'AIR2::SrcSpecialty',
            column_map => { user_id => 'ss_upd_user' },
            type       => 'one to many',
        },

        src_uri => {
            class      => 'AIR2::SrcUri',
            column_map => { user_id => 'suri_cre_user' },
            type       => 'one to many',
        },

        src_uri_updated => {
            class      => 'AIR2::SrcUri',
            column_map => { user_id => 'suri_upd_user' },
            type       => 'one to many',
        },

        srs_annotation => {
            class      => 'AIR2::SrsAnnotation',
            column_map => { user_id => 'srsan_cre_user' },
            type       => 'one to many',
        },

        srs_annotation_updated => {
            class      => 'AIR2::SrsAnnotation',
            column_map => { user_id => 'srsan_upd_user' },
            type       => 'one to many',
        },

        system_message => {
            class      => 'AIR2::SystemMessage',
            column_map => { user_id => 'smsg_cre_user' },
            type       => 'one to many',
        },

        system_message_updated => {
            class      => 'AIR2::SystemMessage',
            column_map => { user_id => 'smsg_upd_user' },
            type       => 'one to many',
        },

        tag => {
            class      => 'AIR2::Tag',
            column_map => { user_id => 'tag_cre_user' },
            type       => 'one to many',
        },

        tag_master => {
            class      => 'AIR2::TagMaster',
            column_map => { user_id => 'tm_cre_user' },
            type       => 'one to many',
        },

        tag_master_updated => {
            class      => 'AIR2::TagMaster',
            column_map => { user_id => 'tm_upd_user' },
            type       => 'one to many',
        },

        tag_updated => {
            class      => 'AIR2::Tag',
            column_map => { user_id => 'tag_upd_user' },
            type       => 'one to many',
        },

        user => {
            class      => 'AIR2::User',
            column_map => { user_id => 'user_cre_user' },
            type       => 'one to many',
        },

        user_email_address => {
            class      => 'AIR2::UserEmailAddress',
            column_map => { user_id => 'uem_user_id' },
            type       => 'one to many',
        },

        user_updated => {
            class      => 'AIR2::User',
            column_map => { user_id => 'user_upd_user' },
            type       => 'one to many',
        },

        user_orgs_created => {
            class      => 'AIR2::UserOrg',
            column_map => { user_id => 'uo_cre_user' },
            type       => 'one to many',
        },

        user_orgs => {
            class      => 'AIR2::UserOrg',
            column_map => { user_id => 'uo_user_id' },
            type       => 'one to many',
        },

        user_orgs_updated => {
            class      => 'AIR2::UserOrg',
            column_map => { user_id => 'uo_upd_user' },
            type       => 'one to many',
        },

        user_phone_number => {
            class      => 'AIR2::UserPhoneNumber',
            column_map => { user_id => 'uph_user_id' },
            type       => 'one to many',
        },

        user_uri => {
            class      => 'AIR2::UserUri',
            column_map => { user_id => 'uuri_user_id' },
            type       => 'one to many',
        },
    ],
);

sub get_name {
    my $self = shift;
    return join( ', ',
        grep {defined} ( $self->user_last_name, $self->user_first_name ) );
}

1;

